﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PSI.Services;
using Newtonsoft.Json;

namespace PSI.Models.TMS {
    /// <summary>
    /// 出口委托
    /// </summary>
    public class OutConsignation {
        [JsonProperty("id")]
        public string Id { get; set; }

        /// <summary>
        /// 委托单单号
        /// </summary>
        [JsonProperty("billNumber")]
        public string BillNumber { get; set; }

        /// <summary>
        /// 船名
        /// </summary>
        [JsonProperty("vsl")]
        public string Vsl { get; set; }

        /// <summary>
        /// 航次
        /// </summary>
        [JsonProperty("voyNumber")]
        public string VoyNumber { get; set; }

        /// <summary>
        /// 委托方
        /// </summary>
        [JsonProperty("clients")]
        public string Clients { get; set; }

        /// <summary>
        /// 箱量
        /// </summary>
        [JsonProperty("cnt")]
        public string Cnt { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        [JsonProperty("price")]
        public string Price { get; set; }

        /// <summary>
        /// 业务人员
        /// </summary>
        [JsonProperty("bizMan")]
        public string BizMan { get; set; }

        /// <summary>
        /// 接单日期
        /// </summary>
        [JsonProperty("bizDT")]
        public string BizDT { get; set; }

        [JsonProperty("actionDT")]
        public string ActionDT { get; set; }

        /// <summary>
        /// 提箱时限
        /// </summary>
        [JsonProperty("takeCntDT")]
        public string TakeCntDT { get; set; }

        [JsonProperty("takeCntDate")]
        public string TakeCntDate { get; set; }

        [JsonProperty("takeCntTime")]
        public string TakeCntTime { get; set; }

        [JsonProperty("status")]
        public string Status { get; set; }

        [JsonProperty("confirmUserName")]
        public string ConfrimUserName { get; set; }

        [JsonProperty("confirmDT")]
        public string ConfirmDT { get; set; }

        //导入添加字段

        /// <summary>
        /// 装货事项
        /// </summary>
        public string LoadMatter { get; set; }
        /// <summary>
        /// 特殊事项
        /// </summary>
        public string SpecialMatter { get; set; }
        /// <summary>
        /// 起运港
        /// </summary>
        public string StarPort { get; set; }
        /// <summary>
        /// 配送优先级
        /// </summary>
        public string Psyxj { get; set; }
        /// <summary>
        /// 装货地点
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 箱属
        /// </summary>
        public string CntOwner { get; set; }
        /// <summary>
        /// 箱型
        /// </summary>
        public string CntType { get; set; }

        /// <summary>
        /// 箱量
        /// </summary>
        public int CntNum { get; set; }

        /// <summary>
        /// 货名
        /// </summary>
        public string GoodName { get; set; }

        public List<OutConsignationDetail> Items { get; set; }

        /// <summary>
        /// 是否发布微信 0默认 1发布 2不发布 3是已预约
        /// </summary>
        [JsonProperty("i_Isweixin")]
        public IsWXStatus isweixin { get; set; }

    }

    /// <summary>
    /// 出口委托的明细（送货明细）
    /// </summary>
    public class OutConsignationDetail:PSIBaseService {
        [JsonProperty("id")]
        public string Id { get; set; }

        [JsonProperty("parentId")]
        public string ParentId { get; set; }

        /// <summary>
        /// 船名
        /// </summary>
        [JsonProperty("vsl")]
        public string Vsl { get; set; }

        /// <summary>
        /// 航次
        /// </summary>
        [JsonProperty("voyNumber")]
        public string VoyNumber { get; set; }

        /// <summary>
        /// 船名/航次
        /// </summary>
        public string VslandVoy {
            get {
                var str = "";
                if (!string.IsNullOrEmpty(this.Vsl))
                {
                    str += this.Vsl;
                }
                if (!string.IsNullOrEmpty(this.Vsl) || !string.IsNullOrEmpty(this.VoyNumber))
                {
                    str += "/";
                }
                if (!string.IsNullOrEmpty(this.VoyNumber))
                {
                    str += this.VoyNumber;
                }
               return  str;  
            }
        }

        [JsonProperty("cntOwner")]
        public string CntOwner { get; set; }

        [JsonProperty("cntType")]
        public string CntType { get; set; }

        [JsonProperty("cntNumber")]
        public string CntNumber { get; set; }

        [JsonProperty("cntType1")]
        public string CntType1 { get; set; }

        [JsonProperty("cntNumber1")]
        public string CntNumber1 { get; set; }

        [JsonProperty("cntSeal1")]
        public string CntSeal1 { get; set; }

        [JsonProperty("cntType2")]
        public string CntType2 { get; set; }

        [JsonProperty("cntNumber2")]
        public string CntNumber2 { get; set; }

        [JsonProperty("cntSeal2")]
        public string CntSeal2 { get; set; }

        [JsonProperty("address")]
        public string Address { get; set; }

        [JsonProperty("deliverDT")]
        public string DeliverDT { get; set; }

        /// <summary>
        /// 运单号
        /// </summary>
        [JsonProperty("blNumber")]
        public string BlNumber { get; set; }

        /// <summary>
        /// 货主
        /// </summary>
        [JsonProperty("goodsOwner")]
        public string GoodsOwner { get; set; }

        /// <summary>
        /// 货主电话
        /// </summary>
        [JsonProperty("goodsOwnerTel")]
        public string GoodsOwnerTel { get; set; }

        [JsonProperty("goods")]
        public string Goods { get; set; }

        /// <summary>
        /// 装箱联系人
        /// </summary>
        [JsonProperty("loadCntMan")]
        public string LoadCntMan { get; set; }

        /// <summary>
        /// 装箱联系人电话
        /// </summary>
        [JsonProperty("loadCntManTel")]
        public string LoadCntManTel { get; set; }

        /// <summary>
        /// 吨位
        /// </summary>
        [JsonProperty("ton")]
        public string Ton { get; set; }

        /// <summary>
        /// 目的港
        /// </summary>
        [JsonProperty("destPort")]
        public string DestPort { get; set; }


        /// <summary>
        /// 备注
        /// </summary>
        [JsonProperty("memo")]
        public string Memo { get; set; }

        /// <summary>
        /// 计划号
        /// </summary>
        [JsonProperty("planNumber")]
        public string PlanNumber { get; set; }

        /// <summary>
        /// 计划时间
        /// </summary>
        [JsonProperty("plandt")]
        public DateTime PlanDt { get; set; }

        [JsonProperty("trucknum")]
        public string truckNum { get; set; }

        [JsonProperty("status")]
        public string Status { get; set; }

        /// <summary>
        /// 是否发布微信 0默认 1发布 2不发布 3是已预约
        /// </summary>
        [JsonProperty("i_Isweixin")]
        public IsWXStatus isweixin { get; set; }

        public OutConsignation outconsig
        {
            get
            {
                var result = new OutConsignation();

                if (!String.IsNullOrEmpty(this.ParentId))
                {
                    var sql = new System.Text.StringBuilder("select * from tms_out_consignation where id=@id");
                    var p = CreateDbParameters();
                    p.AddWithValue("id", this.ParentId);
                    Query(sql.ToString(), p, reader =>
                    {
                        result.BillNumber = reader.GetString(reader.GetOrdinal("f_bill_num"));
                        result.Vsl = reader.GetString(reader.GetOrdinal("f_vsl"));
                        result.VoyNumber = reader.GetString(reader.GetOrdinal("f_voy_num"));
                        result.Clients = reader.GetString(reader.GetOrdinal("f_clients"));
                        result.TakeCntDT = reader.GetDateTime(reader.GetOrdinal("f_take_cnt_dt")).ToString("yyyy-MM-dd");
                        result.TakeCntTime = reader.GetDateTime(reader.GetOrdinal("f_take_cnt_dt")).ToString("yyyy-MM-dd HH:mm");
                        result.BizMan = reader.GetString(reader.GetOrdinal("f_biz_man"));
                        result.BizDT = reader.GetDateTime(reader.GetOrdinal("f_biz_dt")).ToString("yyyy-MM-dd");
                    });
                }
                return result;
            }
        }

    }

    public class OutPlan {
        [JsonProperty("id")]
        public string Id { get; set; }

        [JsonProperty("planNumber")]
        public string PlanNumber { get; set; }


        /// <summary>
        /// 船名
        /// </summary>
        [JsonProperty("vsl")]
        public string Vsl { get; set; }

        /// <summary>
        /// 航次
        /// </summary>
        [JsonProperty("voyNumber")]
        public string VoyNumber { get; set; }

        /// <summary>
        /// 委托方
        /// </summary>
        [JsonProperty("clients")]
        public string Clients { get; set; }

        /// <summary>
        /// 提箱时限
        /// </summary>
        [JsonProperty("takeCntDT")]
        public string TakeCntDT { get; set; }

        [JsonProperty("cntOwner")]
        public string CntOwner { get; set; }

        [JsonProperty("cntType")]
        public string CntType { get; set; }

        [JsonProperty("cntNumber")]
        public string CntNumber { get; set; }

        [JsonProperty("cntType1")]
        public string CntType1 { get; set; }

        [JsonProperty("cntNumber1")]
        public string CntNumber1 { get; set; }

        [JsonProperty("cntSeal1")]
        public string CntSeal1 { get; set; }

        [JsonProperty("cntType2")]
        public string CntType2 { get; set; }

        [JsonProperty("cntNumber2")]
        public string CntNumber2 { get; set; }

        [JsonProperty("cntSeal2")]
        public string CntSeal2 { get; set; }

        [JsonProperty("address")]
        public string Address { get; set; }

        /// <summary>
        /// 运单号
        /// </summary>
        [JsonProperty("blNumber")]
        public string BlNumber { get; set; }

        /// <summary>
        /// 货主
        /// </summary>
        [JsonProperty("goodsOwner")]
        public string GoodsOwner { get; set; }

        /// <summary>
        /// 货主电话
        /// </summary>
        [JsonProperty("goodsOwnerTel")]
        public string GoodsOwnerTel { get; set; }

        /// <summary>
        /// 装箱联系人
        /// </summary>
        [JsonProperty("loadCntMan")]
        public string LoadCntMan { get; set; }

        /// <summary>
        /// 装箱联系人电话
        /// </summary>
        [JsonProperty("loadCntManTel")]
        public string LoadCntManTel { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [JsonProperty("memo")]
        public string Memo { get; set; }

        /// <summary>
        /// 计划下达时间
        /// </summary>
        [JsonProperty("planDT")]
        public string PlanDT { get; set; }

        /// <summary>
        /// 调度
        /// </summary>
        [JsonProperty("dispatcher")]
        public string Dispather { get; set; }

        /// <summary>
        /// 派车时间
        /// </summary>
        [JsonProperty("truckDT")]
        public string TruckDT { get; set; }

        [JsonProperty("truckCompany")]
        public string TruckCompany { get; set; }

        [JsonProperty("truckNumber")]
        public string TruckNumber { get; set; }

        [JsonProperty("driver")]
        public string Driver { get; set; }

        [JsonProperty("driverTel")]
        public string DriverTel { get; set; }

        [JsonProperty("dt0Plan")]
        public string DT0Plan { get; set; }
        [JsonProperty("dt0PlanDate")]
        public string DT0PlanDate { get; set; }
        [JsonProperty("dt0PlanTime")]
        public string DT0PlanTime { get; set; }

        [JsonProperty("dt0Driver")]
        public string DT0Driver { get; set; }
        [JsonProperty("dt0DriverDate")]
        public string DT0DriverDate { get; set; }
        [JsonProperty("dt0DriverTime")]
        public string DT0DriverTime { get; set; }

        [JsonProperty("dt1Plan")]
        public string DT1Plan { get; set; }
        [JsonProperty("dt1PlanDate")]
        public string DT1PlanDate { get; set; }
        [JsonProperty("dt1PlanTime")]
        public string DT1PlanTime { get; set; }

        [JsonProperty("dt1Driver")]
        public string DT1Driver { get; set; }
        [JsonProperty("dt1DriverDate")]
        public string DT1DriverDate { get; set; }
        [JsonProperty("dt1DriverTime")]
        public string DT1DriverTime { get; set; }

        [JsonProperty("dt2Plan")]
        public string DT2Plan { get; set; }
        [JsonProperty("dt2PlanDate")]
        public string DT2PlanDate { get; set; }
        [JsonProperty("dt2PlanTime")]
        public string DT2PlanTime { get; set; }

        [JsonProperty("dt2Driver")]
        public string DT2Driver { get; set; }
        [JsonProperty("dt2DriverDate")]
        public string DT2DriverDate { get; set; }
        [JsonProperty("dt2DriverTime")]
        public string DT2DriverTime { get; set; }

        [JsonProperty("dt3Plan")]
        public string DT3Plan { get; set; }
        [JsonProperty("dt3PlanDate")]
        public string DT3PlanDate { get; set; }
        [JsonProperty("dt3PlanTime")]
        public string DT3PlanTime { get; set; }

        [JsonProperty("dt3Driver")]
        public string DT3Driver { get; set; }
        [JsonProperty("dt3DriverDate")]
        public string DT3DriverDate { get; set; }
        [JsonProperty("dt3DriverTime")]
        public string DT3DriverTime { get; set; }

        [JsonProperty("dt4Plan")]
        public string DT4Plan { get; set; }
        [JsonProperty("dt4PlanDate")]
        public string DT4PlanDate { get; set; }
        [JsonProperty("dt4PlanTime")]
        public string DT4PlanTime { get; set; }

        [JsonProperty("dt4Driver")]
        public string DT4Driver { get; set; }
        [JsonProperty("dt4DriverDate")]
        public string DT4DriverDate { get; set; }
        [JsonProperty("dt4DriverTime")]
        public string DT4DriverTime { get; set; }

        [JsonProperty("traceMemo")]
        public string TraceMemo { get; set; }

        /// <summary>
        /// 吨位
        /// </summary>
        [JsonProperty("ton")]
        public string Ton { get; set; }

        /// <summary>
        /// 目的港
        /// </summary>
        [JsonProperty("destPort")]
        public string DestPort { get; set; }

        /// <summary>
        /// 货名
        /// </summary>
        [JsonProperty("goods")]
        public string Goods { get; set; }

        /// <summary>
        /// 趟次号
        /// </summary>
        [JsonProperty("tripNumber")]
        public string TripNumber { get; set; }

        [JsonProperty("status")]
        public string Status { get; set; }

        [JsonProperty("srvLevel")]
        public string SrvLevel { get; set; }

        [JsonProperty("srvClientsMemo")]
        public string SrvClientsMemo { get; set; }
    }

    public class OutUploadData {
        public string BillNumber { get; set; }
        /// <summary>
        /// 船名
        /// </summary>
        public string Vsl { get; set; }
        /// <summary>
        /// 航次
        /// </summary>
        public string VoyNumber { get; set; }
        /// <summary>
        /// 托运人
        /// </summary>
        public string Clients { get; set; }
        /// <summary>
        /// 装货日期
        /// </summary>
        public string TakeCntDT { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string BizMan { get; set; }
        public string BizDT { get; set; }
        /// <summary>
        /// 运单号
        /// </summary>
        public string BLNumber { get; set; }
        /// <summary>
        /// 箱属
        /// </summary>
        public string CntOwner { get; set; }
        /// <summary>
        /// 箱型
        /// </summary>
        public string CntType { get; set; }
        /// <summary>
        /// 箱量
        /// </summary>
        public string CntCount { get; set; }
        /// <summary>
        /// 装货地点
        /// </summary>
        public string Address { get; set; }
        public string GoodsOwner { get; set; }
        /// <summary>
        /// 货重
        /// </summary>
        public string GoodsWeight { get; set; }
        /// <summary>
        /// 货名
        /// </summary>
        public string Goods { get; set; }
        /// <summary>
        /// 装货事项
        /// </summary>
        public string LoadMatter { get; set; }
        /// <summary>
        /// 特殊事项
        /// </summary>
        public string SpecialMatter { get; set; }
        /// <summary>
        /// 起运港
        /// </summary>
        public string StarPort { get; set; }
        /// <summary>
        /// 配货优先级
        /// </summary>
        public string Psyxj { get; set; }

        public string LoadMan { get; set; }
        public string LoadManMobileTel { get; set; }
        public string LoadManTel { get; set; }
    }
}